using UnityEngine;

public class optionUI : MonoBehaviour
{
	private GameObject optionobj;

	public UIEventListener musicbtn;

	public UIEventListener sfxbtn;

	public UIEventListener invertybtn;

	public UIEventListener buttonctlbtn;

	public UIEventListener gravityctlbtn;

	public UIEventListener closebtn;

	public UIEventListener creditsbtn;

	public UISprite musicselect;

	public UISprite sfxselect;

	public UISprite yselect;

	public UISprite btnselect;

	public UISprite graselect;

	public Animator animator;

	private bool isshow;

	private void Start()
	{
		musicbtn.onClick = OnClickmusicBtn;
		sfxbtn.onClick = OnClicksfxBtn;
		invertybtn.onClick = OnClickyBtn;
		buttonctlbtn.onClick = OnClickbuttonctlBtn;
		gravityctlbtn.onClick = OnClickgravityctlBtn;
		closebtn.onClick = OnClickcloseBtn;
		creditsbtn.onClick = OnClickcreditsBtn;
	}

	public void initinfo()
	{
		if (GlobalInf.PlaneCtrlType == PLANECTRLTYPE.BUTTON)
		{
			btnselect.enabled = true;
			graselect.enabled = false;
		}
		else
		{
			btnselect.enabled = false;
			graselect.enabled = true;
		}
		if (GlobalInf.ismusic)
		{
			musicselect.transform.localPosition = new Vector3(-24f, 0f, 0f);
		}
		else
		{
			musicselect.transform.localPosition = new Vector3(24f, 0f, 0f);
		}
		if (GlobalInf.issfx)
		{
			sfxselect.transform.localPosition = new Vector3(-24f, 0f, 0f);
		}
		else
		{
			sfxselect.transform.localPosition = new Vector3(24f, 0f, 0f);
		}
		if (GlobalInf.isinverty)
		{
			yselect.transform.localPosition = new Vector3(-24f, 0f, 0f);
		}
		else
		{
			yselect.transform.localPosition = new Vector3(24f, 0f, 0f);
		}
		if (MidLoading.loadlevel != 2)
		{
			animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
			Invoke("animplay", Time.deltaTime * 2f);
		}
	}

	public void enable()
	{
		if (optionobj == null)
		{
			optionobj = base.gameObject;
		}
		initinfo();
		NGUITools.SetActive(optionobj, state: true);
		isshow = true;
	}

	public void OnClickmusicBtn(GameObject btn)
	{
		if (GlobalInf.ismusic)
		{
			musicselect.transform.localPosition = new Vector3(24f, 0f, 0f);
			GlobalInf.ismusic = false;
			PlayerPrefs.SetInt("ismusic", 0);
			MonoInstance<AudioController>.instance.turnOffMusic();
			return;
		}
		musicselect.transform.localPosition = new Vector3(-24f, 0f, 0f);
		GlobalInf.ismusic = true;
		PlayerPrefs.SetInt("ismusic", 1);
		if (MidLoading.loadlevel == 0)
		{
			MonoInstance<AudioController>.instance.turnOnMusic();
		}
	}

	public void OnClicksfxBtn(GameObject btn)
	{
		if (GlobalInf.issfx)
		{
			sfxselect.transform.localPosition = new Vector3(24f, 0f, 0f);
			GlobalInf.issfx = false;
			PlayerPrefs.SetInt("issfx", 0);
		}
		else
		{
			sfxselect.transform.localPosition = new Vector3(-24f, 0f, 0f);
			GlobalInf.issfx = true;
			PlayerPrefs.SetInt("issfx", 1);
		}
	}

	public void OnClickyBtn(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
		if (GlobalInf.isinverty)
		{
			yselect.transform.localPosition = new Vector3(24f, 0f, 0f);
			GlobalInf.isinverty = false;
			PlayerPrefs.SetInt("isinverty", 0);
		}
		else
		{
			yselect.transform.localPosition = new Vector3(-24f, 0f, 0f);
			GlobalInf.isinverty = true;
			PlayerPrefs.SetInt("isinverty", 1);
		}
	}

	public void OnClickbuttonctlBtn(GameObject btn)
	{
		if (GlobalInf.PlaneCtrlType != 0)
		{
			GlobalInf.PlaneCtrlType = PLANECTRLTYPE.BUTTON;
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
			if (MidLoading.loadlevel == 2)
			{
				UIController.instance.setcontrollUI();
			}
			btnselect.enabled = true;
			graselect.enabled = false;
			PlayerPrefs.SetInt("controltype", 0);
		}
	}

	public void OnClickgravityctlBtn(GameObject btn)
	{
		if (GlobalInf.PlaneCtrlType != PLANECTRLTYPE.GRAVITY)
		{
			GlobalInf.PlaneCtrlType = PLANECTRLTYPE.GRAVITY;
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
			if (MidLoading.loadlevel == 2)
			{
				UIController.instance.setcontrollUI();
			}
			btnselect.enabled = false;
			graselect.enabled = true;
			PlayerPrefs.SetInt("controltype", 1);
		}
	}

	public void OnClickcreditsBtn(GameObject btn)
	{
		if (MidLoading.loadlevel == 0)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
			disable();
			MenuUIController.instance.enable_creditsui();
		}
		else
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
			GameUIController.instance.enable_inter();
		}
	}

	public void animplay()
	{
		/* scaleanima["PopWinAnimation"].time = 0f;
		scaleanima["PopWinAnimation"].speed = 1f;
		scaleanima.Play(); */
		animator.SetTrigger("popWin1");
	}

	public void OnClickcloseBtn(GameObject btn)
	{
		if (isshow)
		{
			isshow = false;
			if (MidLoading.loadlevel == 2)
			{
				GameUIController.instance.disable_optionui();
			}
			else
			{
				/* scaleanima["PopWinAnimation"].time = scaleanima.clip.length;
				scaleanima["PopWinAnimation"].speed = -1f;
				scaleanima.Play(); */
				animator.SetTrigger("popWin2");
				Invoke("disable", animator.runtimeAnimatorController.animationClips[0].length);
			}
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
		}
	}

	public void disable()
	{
		if (optionobj == null)
		{
			optionobj = base.gameObject;
		}
		NGUITools.SetActive(optionobj, state: false);
		if (MidLoading.loadlevel == 2)
		{
			gamebackctl.instance.BackGameUIstate();
		}
		else
		{
			MenuBackController.instance.BackMenuUIstate();
		}
	}
}
